import { defineStore } from 'pinia'
import { ref } from 'vue' // 需要使用ref否则从store取不到数据

// 写法1
export const useSelectOptionsStore = defineStore(
    'selectOptions',
    () => {
        const companyOptions = ref([])
        const setCompanyOptions = (data) => {
            companyOptions.value = data
        }
        const allProjectOptions = ref([])
        const setAllProjectOptions = (data) => {
            allProjectOptions.value = data
        }
        const allSiteOptions = ref([])
        const setAllSiteOptions = (data) => {
            allSiteOptions.value = data
        }
        return { companyOptions, setCompanyOptions, allProjectOptions, setAllProjectOptions, allSiteOptions, setAllSiteOptions, }
    },
    {
        persist: {
            key: 'customKey-optionsData', // 存储的key,默认为store的id,例如本store的id为selectOptions
            storage: localStorage, // sessionStorage/localStorage (默认存储位置为localStorage)
            // paths: ['companyOptions'], // 可选选择需要存储的数据(默认全部存储)
        }
    }
)

// 写法2
// export const useSelectOptionsStore = defineStore('selectOptions', {
//     state: () => ({
//         companyOptions: [],
//         allProjectOptions: [],
//         allSiteOptions: []
//     }),
//     actions: {},
//     getters: {},
//     persist: true
// })